import json
import time
from .gegtPublicData import *

def getPieBrandData():
    cars = list(getAllCars())
    carsVolume = {}
    for car in cars:
        if carsVolume.get(car.brandName,-1) == -1:
            carsVolume[str(car.brandName)] = int(car.sale)
        else:
            carsVolume[str(car.brandName)] += int(car.sale)
    carsVolume = sorted(zip(carsVolume.values(),carsVolume.keys()),reverse=True)
    sortDict = {car[1]:car[0] for car in carsVolume}
    lastPieList = []
    for k,v in sortDict.items():
        lastPieList.append({
            'name':k,
            'value':v
        })
    print(lastPieList)
    return lastPieList[:10]